﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private int id;
        private object id1;
        private object name;
        private object age;
        private object score;

        public Form2(int id, string name, int age, int score)
        {
            InitializeComponent();
            this.id = id;
            maskedTextBox1.Text = name;
            maskedTextBox2.Text = age.ToString();
            maskedTextBox3.Text = score.ToString();

        }

        public Form2(object id1, object name, object age, object score)
        {
            this.id1 = id1;
            this.name = name;
            this.age = age;
            this.score = score;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var name = maskedTextBox1.Text;
            var age = maskedTextBox2.Text;
            var score = maskedTextBox3.Text;





            if (this.id > 0)

            {
                var sql = string.Format("updata student set studentname='{0}',age={1},score={2}where id{3}", Name, age, score, this.id);
                DbHelper.Addupdate(sql);
                MessageBox.Show("更新成功！", "提示");
            }
            else
            {
                var sql = string.Format("insert into student(studentage,age,score)values('{0}',{1},{2})", name, age, score);
                DbHelper.Addupdate(sql);
                MessageBox.Show("添加成功", "提示");

            }
            this.DialogResult = DialogResult.Yes;

            this.Close();
        }
    }
}
